home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr53
/
pctv4n_1.zip
/
STACK.CPP
< prev
next >
Wrap
Text File
|
1993-06-10
|
1KB
|
55 lines
#include <dos.h>
#include <mem.h>
#if sizeof(void *) != sizeof(void far *)
#error This code assumes a large data model.
#endif
// Skip first 512 bytes to accommodate emulator.
#define TEST_BASE 0x0200
#define STACK_VAL 0x66
///
// Fill stack with STACK_VAL.
void fillStack() {
asm {
mov ax, ss // Point ES:DI to SS:TEST_BASE.
mov es, ax
mov di, TEST_BASE
mov al, STACK_VAL // STACK_VAL marks unused stack.
cld // Forward store.
mov cx, sp // Stack pointer minus TEST_BASE
sub cx, TEST_BASE // is length of store.
rep stosb // Fill stack.
}
}
///
// Check stack watermark.
unsigned stackMin() {
asm {
mov ax, ss // Point ES:DI to SS:TEST_BASE.
mov es, ax
mov di, TEST_BASE
mov al, STACK_VAL // STACK_VAL marks unused stack.
cld // Forward search.
mov cx, _stklen // Stack length minus TEST_BASE
sub cx, TEST_BASE // is length of search.
repe scasb // Find first non-matching byte.
dec di // DI holds offset after first byte
mov ax, di // that doesn't match.
}
// Return value is amount of stack still free.
return (_AX);
}